"""
要素的内容抽取及语义审查的合并api接口
"""
from typing import Any, Dict
from fastapi import Body
from core.rule_extract import rule_extract_api
from core.rule_review import rule_review_api
from server.api_wrap import async_api_wrapper, BaseResponse


@async_api_wrapper
async def rule_api(
        fileId: str = Body(description='文件id', examples=['dad6204ebdb84513b3afb175e462b']),
        rule: Dict[str, Any] = Body(description='要素的内容抽取及语义审查', examples=[
            {'id': "123", 'name': "XXX", 'extractHint': "YYY", 'checkHint': "ZZZ"}])
):
    if 'checkHint' not in rule:
        result = await rule_extract_api(fileId, rule)
    elif rule['checkHint'] is None or rule['checkHint'] == '':
        result =  await rule_extract_api(fileId, rule)
    else:
        result =  await rule_review_api(fileId, rule)
    return BaseResponse(data=result)